//
//  main.c
//  Questions
//
//  Created by wangrui on 14-09-16.
//  Copyright (c) 2014年 PPS. All rights reserved.
//

#include <stdio.h>
#include <stdlib.h>

void printArray(int a[], int count)
{
	for (int k=0; k<count; k++) {
		printf("%d ",a[k]);
	}
	
	printf("\n");
}

void bobSort(int a[], int length) {
	for (int i=1; i<length; i++) {
		
		int flag = 0;
		
		for (int j=0; j < length-i; j++) {
			
			if (a[j] > a[j+1]) {
				
				int t = a[j+1];
				a[j+1] = a[j];
				a[j] = t;
				
				flag = 1;
			}
		}
		
		if (flag == 0) {
			break;
		}
	}
}

int main(int argc, const char * argv[])
{
	int sorted[] = {5,7,9,10,2,4,5,6,7,100,22,53};
	
	bobSort(sorted, 12);
	
	printArray(sorted, 12);
	
	return 0;
}


